package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.AttrsListBean;
import com.sgb.jicai.entity.GoodsDetailBean;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * Time:2021/8/11
 * AUTHOR:F_Q
 * Description:
 */
public class DetailedTwoAdapter  extends BaseRecycleAdapter<AttrsListBean> {

    public DetailedTwoAdapter(Context activity, List<AttrsListBean> list) {
        super(activity, R.layout.item_jc_detailed_two, list);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        ItemInputTextView names = holder.itemView.findViewById(R.id.name);
        names.setLabelName(datas.get(position).getName()+"");
        if (!TextUtils.isEmpty(datas.get(position).getVal())){
            names.setContent(datas.get(position).getVal()+"");
        }else {
            names.setContent("");
        }
        if (!TextUtils.isEmpty(datas.get(position).getName())){
            names.setLabelHint("请选择"+datas.get(position).getName()+"");
        }else {
            names.setLabelHint("请选择");
        }
        names.setOnWholeItemClickListener(new ItemInputTextView.OnWholeItemClickListener() {
            @Override
            public void OnWholeItemClick(View view) {
                showListPop("",names,datas.get(position));
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, AttrsListBean entity) {
        holder.setBinding(BR.viewModel, entity);

    }
    /**
     * 一级选择弹窗
     *
     * @param titles
     * @param inputTextView
     * @param data
     */
    private void showListPop(String titles, ItemInputTextView inputTextView,AttrsListBean data) {
        List<GoodsDetailBean> goodsDetailBeans = data.getGoodsDetailBeans();
        if (goodsDetailBeans==null||goodsDetailBeans.size()==0){
            MToast.showToast(context,"没有数据信息！");
            return;
        }
        if (goodsDetailBeans != null && goodsDetailBeans.size() > 0) {
            OptionsPickerView<GoodsDetailBean> mCustomerOptions = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    inputTextView.setContent(goodsDetailBeans.get(options1).getBrandName());
                    data.setVal(goodsDetailBeans.get(options1).getBrandName());
                    data.setValue(goodsDetailBeans.get(options1).getBrandName());
                }
            }).setCancelColor(Color.parseColor("#666666"))
                    .setSubCalSize(15)
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitColor(Color.parseColor("#5792FD")).build();
            mCustomerOptions.setTitleText(titles);
            mCustomerOptions.setPicker(goodsDetailBeans);
            mCustomerOptions.setSelectOptions(0);
            mCustomerOptions.show();
        }
    }
}
